#include "VMVirtualMemory.h"



//default constructor
VMVirtualMemory::VMVirtualMemory()
{
	mapper = NULL;
	memory = VMPhysicalMemory();
}

//constructor sets the memory scheme and physical memory
VMVirtualMemory::VMVirtualMemory(VMMemoryScheme* map, VMPhysicalMemory& mem)
{
	mapper = map;
	memory = mem;
}
//get word size in bits
unsigned long int VMVirtualMemory::getWordSize()
{
	return mapper->getWordSize(); //returns word size of virtual memory.
}
//get the address size
unsigned long int VMVirtualMemory::getAddressSize()
{
	return mapper->getAddressSize();
}
//gets a word from memory virtual memory
unsigned char* VMVirtualMemory::getWord(unsigned long int address,
					unsigned char* buffer)
{
	//create the buffer to store word
	unsigned char* virtualWord = buffer;
	//reads the virtual word.
	virtualWord = mapper->readVirtualWord(&memory, virtualWord, address);
	return virtualWord;
}

//sets a word in memory
void VMVirtualMemory::setWord(unsigned long int address, unsigned char* word)
{
	mapper->writeVirtualWord(&memory, word, vaddr);
}
//sets a set of words from memory
void VMVirtualMemory::setWords(unsigned long int startAddress, 
		unsigned char** words,
		unsigned long int numberOfWords)
{
	unsigned int i = 0;
	for(i = 0; i < numberOfWords; i++)
	{
		setWord(startAddress+i, words[i]);
	}
}
//gets a set of words from memory
unsigned char** VMVirtualMemory::getWords(unsigned long int startAddress,
	   		   unsigned long int numberOfWords,
				unsigned char** buffer)
{
	unsigned int i = 0;
	for(i = 0; i < numberOfWords; i++)
	{
		buffer[i] = getWord(startAddress + i, buffer[i]);
	}
}

